<?php

App::import('module','admin/admincontroller');

Class PaginaController extends AdminController
{    
	public $uses = array('pagina');
	
	public function index()
    {      	
    	$filtro = new QueryFilter();
    	$filtro->command = 'ORDER BY nivel ASC';
    	
		$paginas = $this->Pagina->all($filtro);
		$this->set('paginas',$paginas);	
    }

    public function add()
    {      	    	
    	if(!empty($this->data))
    	{    	
    		$id = $this->Pagina->Save($this->data);
    		$this->_context->redirectUrl('admin.pagina');
    	}    	
    	$this->set("tipo",array('p'=>'Pública','r'=>'Restrita'));
    	$this->_context->addHelper('fkeditor');
    }  
  
    
    public function edit($id = null)
    {    	
    	if(!$id && empty($this->data))
    	{    		
    		$this->_context->redirectUrl('admin.pagina');
    	}    	
    	if(!empty($this->data))
    	{     		
    		$this->data['Pagina']['html'] = str_replace('/webroot','',$this->data['Pagina']['html']);
    		$id = $this->Pagina->Save($this->data);
    		$this->_context->redirectUrl('admin.pagina');
    	}
    	if (empty($this->data)) {
			$this->createData($this->Pagina->findForId($id),$this->Pagina);
		}
		$this->_context->addHelper('fkeditor');
    }
    
    public function del($id)
    {    	
    	if(!$id)
    	{    		
    		$this->_context->redirectUrl('admin.pagina');
    	}

    	$this->Pagina->Delete($id); 
    	$this->_context->redirectUrl('admin.pagina');
    }
    
    public function Setup()
    {
    	parent::Setup();    	 	
    }
}
?>
